const privateMsg = require('../models/privateMsg')
const liveMsg = require('../models/liveMsg')
const Sequelize = require('sequelize');
const Op = Sequelize.Op;

class privateMsgDao {
  // 创建
  static async create(v) {    
    const res = await privateMsg.create(
      v
    )
    return res
  }
  // 获取信息
  static async findAllMsg(v1,v2) {
    const res = await privateMsg.findAll({
      where:{
        [Op.or]: [{sender: v1,receiver:v2}, {sender: v2,receiver:v1}]
      }
    });
    return res
  }
  // 删除
  static async delById(v) {
    const res = await privateMsg.destroy({
      where:{
        id:v
      }
    })
    return res
  }
  // 修改某条数据
  static async upd(v) {
    const res = await privateMsg.update(v, {
      where: {
        id: v.id
      }
    })
    return res
  }
}

module.exports = privateMsgDao